package com.lagou.mr.speakBean;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SpeakDurationMapper extends Mapper<LongWritable, Text,Text,SpeakBean> {
    SpeakBean v = new SpeakBean();
    Text k = new Text();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, SpeakBean>.Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split("\t");
        String deviceID = fields[1];
        long setDuration = Long.parseLong(fields[fields.length - 3]);
        long thirdPartDuration = Long.parseLong(fields[fields.length - 2]);

        k.set(deviceID);
        v.set(setDuration,thirdPartDuration);

        context.write(k,v);
    }
}
